import React from 'react'
import { Route, Switch, withRouter } from 'react-router-dom'
import ErrorPage from '../Layout/ErrorPage'
import NotFound from '../Layout/NotFound'
import layout from '../decorators/layout'

//页面
import Login from '../pages/login'
import Home from '../pages/home'
//高阶组件
const createComponent = (Component, title, noLayout, breakData) => () => {
  if (Component) {
    document.title = title || ''
    let MyComponent = !noLayout ? withRouter(layout(Component)) : withRouter(Component)
    return <MyComponent breadcrumb={{ Pages: [], breakData }} />
  }
}
export default () => (
  <Switch>
    {/*首页*/}
    <Route path="/" exact component={createComponent(Home, '首页', 0)} />
    {/*登录*/}
    <Route path="/login" exact component={createComponent(Login, '登录', 1)} />
    {/*错误页面*/}
    <Route path="/error" exact component={ErrorPage} />
    {/*未找到页面，404*/}
    <Route component={NotFound} />
  </Switch>
)
